package com.wangsd.web.shop.service;

import com.gitee.fastmybatis.core.query.Query;
import com.gitee.fastmybatis.core.query.Sort;
import com.wangsd.web.shop.entity.MemberIntegral;
import com.wangsd.web.shop.mapper.MemberIntegralMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MemberIntegralService {
    @Resource
    MemberIntegralMapper mapper;

    public void save(Integer integral, String miniOpenid, String outTradeNo, Integer type, String description) {
        //保存积分明细记录
        MemberIntegral memberIntegral = new MemberIntegral();
        memberIntegral.setIntegral(integral);
        memberIntegral.setMiniOpenid(miniOpenid);
        memberIntegral.setOutTradeNo(outTradeNo);
        memberIntegral.setType(type);
        memberIntegral.setDescription(description);
        mapper.saveIgnoreNull(memberIntegral);
    }


    public List<MemberIntegral> selectByMiniOpenid(String miniOpenid) {
        Query query = new Query();
        query.eq("mini_openid", miniOpenid);
        query.orderby("created_time", Sort.DESC);
        return mapper.list(query);
    }
}
